#include "guiterm.hpp"
#ifndef COMMANDHANDLER_HPP
#define COMMANDHANDLER_HPP

class Session
	:public QObject
{
	Q_OBJECT
public:
	Session(ServerConnection *host);
	~Session();
	
	void begin();
	void reportError(string message);
	
	Tab *getTab();
	ServerConnection *getHost();
	CommandPrompt *getPrompt();
	CharacterViewConfig *getTerminalSettings();
	
	void addSegment(ViewSegment *segment);
	
	void typedCommand(string cmd);
	void mousedCommand(string cmd);
	void unconfirmedCommand(string cmd);
	void doCommand(string cmd, bool clearPrompt);
	
	pair<int,int> getTerminalSize(int reservedHeight);
	void giveFocus();
	void addLeftoverInput(string text);
	
	string getPromptText();
	void setPromptText(string text);
	void tabCompletionReceived(string prefix, string suffix);
	
	void setLocalDir(string path);
	string getLocalDir();
	
	void exit();
	
	void jobBackgrounded(RemoteJob *job);
	void jobFinished(RemoteJob *job, int result);
	
	void showPrompt(bool focus);
	void hidePrompt(bool reset=true);
	
protected slots:
	void handlePendingInput();
	
signals:
	void finished();
	
protected:
	void setCurrentJob(RemoteJob *job);
	
	ServerConnection *host;
	CharacterViewConfig terminalSettings;
	
	string pendingInput;
	RemoteJob *currentJob;
	
	Tab *tab;
	CommandPrompt *prompt;
	bool promptVisible;
	
	string promptText;
	string localDir;
};

#endif
